package cn.yunbamboos.rest.service.apidoc.meta;

import cn.yunbamboos.rest.service.apidoc.IMeta;
import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Paths implements IMeta {

    private final List<PathItem> items = new ArrayList<>();

    @Override
    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        Collections.sort(items);
        for (PathItem item : this.items) {
            json.put(item.getUrl(), item.toJSON());
        }
        return json;
    }

    public void addPathItem(PathItem pathItem) {
        items.add(pathItem);
    }
}
